import java.util.Random;
import java.util.Scanner;

/**
 * Created by Administrator on 2022/8/2.
 */
public class Demo {
    public static void main(String[] args) {
        //judgeIf();
        //judgeIfElse();
        //judgeIfElseIFElse();
        //judgeSwitch();
        //loopWhile();
        //endBreak();
        //outContinue();
        //loopFor();
        //output();
        //input();
        //loopInput();
        guessNum();
    }
    public static void judgeIf() {
        int a = 6;
        if(a < 7){
            System.out.println("yes");
        }
    }

    public static void judgeIfElse() {
        int a = 16;
        if(a % 2 == 0){
            System.out.println("偶数");
        }else{
            System.out.println("奇数");
        }
    }

    public static void judgeIfElseIFElse() {
        Scanner scan = new Scanner(System.in);
        int a =  scan.nextInt();
        if(a > 0){
            System.out.println("正数");
        }else if(a < 0){
            System.out.println("负数");
        }else{
            System.out.println("零");
        }
    }

    public static void judgeSwitch() {
        int a = 90;
        switch (a / 10){
            case 10:
            case 9:
            case 8:
                System.out.println("优秀");
                break;
            case 7:
            case 6:
                System.out.println("一般");
                break;
            case 5:
            case 4:
            case 3:
            case 2:
            case 1:
            case 0:
                System.out.println("差");
                break;
            default:
                System.out.println("输入错误");
                break;
        }
    }

    public static void loopWhile() {
        int a = 10;//循环变量初始值设置
        while(a > 0){//循环结束条件
            System.out.println(a);
            a--;// 循环变量更新方式
        }
    }

    public static void endBreak() {
        // 找到 100 - 200 中第一个 3 的倍数
        int a = 100;
        while(a <= 200){
            if(a % 3 == 0){
                System.out.println(a);
                break;//直接结束循环
            }
            a++;
        }
    }

    public static void outContinue() {
        //找到 100 - 200 中所有 3 的倍数
        int a = 100;
        while(a <= 200){
            if(a % 3 != 0){
                a++;
                continue;
            }
            System.out.println(a);
            a++;
        }
    }

    public static void loopFor() {
        for (int i = 0; i < 10; i++) {
            System.out.println(i);
        }
    }

    public static void loopDoWhile() {
        int a = 0;
        do{
            System.out.println(a);
            a++;
        }while(a < 10);
    }

    public static void output() {
        int a = 10;
        System.out.println(a);//输出a，并换行
        System.out.print(a);//输出a，不换行
        System.out.printf("%d",a);//以格式化的形式输出a
    }

    public static void input() {
        int a = 0;
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入");
        String str = scan.nextLine();
        System.out.println(str);
        System.out.print("请输入a的值：");
        a = scan.nextInt();
        System.out.println(a);
    }

    public static void loopInput() {
        Scanner scan = new Scanner(System.in);
        int sum = 0;
        while (scan.hasNextInt()){
            int a = scan.nextInt();
            sum += a;
        }
        System.out.println(sum);
        scan.close();// // 注意, 要记得调用关闭方法
    }

    public static void guessNum() {
        //猜数字游戏
        Random rand = new Random();
        Scanner scan = new Scanner(System.in);
        int r = rand.nextInt(100);
        System.out.println(r);
        while(true){
            System.out.println("请输入猜的数字：");
            int s = scan.nextInt();
            if(s > r){
                System.out.println("大了");
            }else if(s < r){
                System.out.println("小了");
            }else{
                System.out.println("猜对了");
                break;
            }
        }
        scan.close(); // 注意, 要记得调用关闭方法
    }
}
